define(['jquery', 'bootstrap', 'backend', 'addtabs', 'table', 'echarts', 'echarts-theme', 'template'], function ($, undefined, Backend, Datatable, Table, Echarts, undefined, Template) {
	
	/* 获取从后端tdsum.php传过来的数据 */
	
	var obj=eval(Config.demo);
	var TIMES=new Array;
	var YCM=new Array;
	var YCJT=new Array;
	var NAMES=new Array;
	var YCSTARTTIMES=new Array;
	//$("#equips").val("9999999999");
	var parzz=/^BP[ACDFGIJW]\d{2}(\.\d)?/;
    var Controller = {
		
        add: function () {

			   $.ajax({
				   type: 'POST',
					url:"http://172.31.3.27:84/index.php?s=/fastadmin/Tdsum/selectYiChangJiTai",
						
					dataType: 'JSON',
					success: function (ret) {
						$("#table_all tbody").html("");
						$("#table_gj tbody").html("");
						$("#table_hx tbody").html("");
						$("#table_dj tbody").html("");
						$("#table_qg tbody").html("");
						$("#table_fg tbody").html("");
						$("#table_bd tbody").html("");
						$("#table_fix tbody").html("");
						$("#table_first tbody").html("");
						/* 各站待机数 OffEquips*/
						//console.log(ret['JT']);
						var objs=eval(ret['JT']);
						var idall=0;
						var idgj=0;
						var idhx=0;
						var iddj=0;
						var idqg=0;
						var idfg=0;
						var idbd=0;
						var idfix=0;
						var idfirst=0;
						
						for(var k in ret['JT'])
							{
								
								if(parzz.test(ret['JT'][k]['异常码'])){
									console.log(ret['JT'][k]['异常码']+'--'+'yes');
								}else{
									//console.log(ret['JT'][k]['异常码']+'--'+'no');
								}
								
								
								YCJT[k]=(ret['JT'][k]['YiChangJiTai']);
								YCM[k]=ret['JT'][k]['异常原因'];
								NAMES[k]=ret['JT'][k]['报修人'];
								YCSTARTTIMES[k]=ret['JT'][k]['YiChangStartTime'];
								TIMES[k]=ret['JT'][k]['times'];
								if(ret['JT'][k]['YiChangEndTime']==" "){
									
									var htmls="<td>"+ret['JT'][k]['YiChangJiTai']+"</td>"
										+"<td>"+ret['JT'][k]['异常原因']+"</td>"
										+"<td>"+ret['JT'][k]['报修人']+"</td>"
										+"<td>"+ret['JT'][k]['处理人']+"</td>"
										+"<td>"+ret['JT'][k]['处理人分组']+"</td>"
										+"<td>"+ret['JT'][k]['YiChangStartTime']+"</td>"
										+"<td>"+ret['JT'][k]['times']+"</td>";
									
									if(YCJT[k]){
										idall+=1;
										var ID = "<td>"+idall+"</td>";
										//console.log(htmls);//+"--"+YCJT+"=="+YCM+"--"+YCSTARTTIMES
										$("<tr></tr>")
										.append(ID)
										.append(htmls)
										.appendTo("#table_all tbody ");//将td放入tr内在放入tbody
										
									}
									if(YCJT[k].substring(0,3)=='BPA'){
										idgj+=1;
										var ID = "<td>"+idgj+"</td>";
										$("<tr></tr>")
										.append(ID)
										.append(htmls)
										.appendTo("#table_gj tbody ");//将td放入tr内在放入tbody
									}
									if(YCJT[k].substring(0,3)=='BPC'){
										idhx+=1;
										var ID = "<td>"+idhx+"</td>";
										$("<tr></tr>")
										.append(ID)
										.append(htmls)
										.appendTo("#table_hx tbody ");//将td放入tr内在放入tbody
									}
									if(YCJT[k].substring(0,3)=='BPD'){
										iddj+=1;
										var ID = "<td>"+iddj+"</td>";
										$("<tr></tr>")
										.append(ID)
										.append(htmls)
										.appendTo("#table_dj tbody ");//将td放入tr内在放入tbody
									}
									if(YCJT[k].substring(0,3)=='BPG'){
										idqg+=1;
										var ID = "<td>"+idqg+"</td>";
										$("<tr></tr>")
										.append(ID)
										.append(htmls)
										.appendTo("#table_qg tbody ");//将td放入tr内在放入tbody
									}
									if(YCJT[k].substring(0,3)=='BPI'){
										idfg+=1;
										var ID = "<td>"+idfg+"</td>";
										$("<tr></tr>")
										.append(ID)
										.append(htmls)
										.appendTo("#table_fg tbody ");//将td放入tr内在放入tbody
									}
									if(YCJT[k].substring(0,3)=='BPJ'){
										idbd+=1;
										var ID = "<td>"+idbd+"</td>";
										$("<tr></tr>")
										.append(ID)
										.append(htmls)
										.appendTo("#table_bd tbody ");//将td放入tr内在放入tbody
									}
									/* 维修，首件 */
									if(YCM[k]==='更换耗材'||YCM[k]==='工单切换调机'||YCM[k]==='设备故障调机'||parzz.test(ret['JT'][k]['异常码'])){
										idfix+=1;
										var ID = "<td>"+idfix+"</td>";
										$("<tr></tr>")
										.append(ID)
										.append(htmls)
										.appendTo("#table_fix tbody ");//将td放入tr内在放入tbody
									}
									if(YCM[k]==='生产调机首检'||YCM[k]==='换单首检'||YCM[k]==='换耗材首检'){
										idfirst+=1;
										var ID = "<td>"+idfirst+"</td>";
										$("<tr></tr>")
										.append(ID)
										.append(htmls)
										.appendTo("#table_first tbody ");//将td放入tr内在放入tbody
									}
									
		
									
								}
								//OffEquips[k]=-(ret['JT'][k]['OffEquips']);
								
							}
						
					}
				});
			
            
			
            $(document).on("click", ".btn-checkversion", function(){
                top.window.$("[data-toggle=checkupdate]").trigger("click");
            });
			
			
			
        },
		
		
		fixandfirst: function () 
		{
		   
			   $.ajax({
				   type: 'POST',
					url:"http://172.31.3.27:84/index.php?s=/fastadmin/Tdsum/selectYiChangJiTai",
					
					dataType: 'JSON',
					success: function (ret) {
						/* 清空tbody内容 */
						$("#table_fixandfirst tbody").html("");
						$("#table_fixend tbody").html("");
						$("#table_fixin tbody").html("");
						$("#table_QCend tbody").html("");
						$("#table_QCin tbody").html("");
						/* 各站待机数 OffEquips*/
						//console.log(ret['JT']);
						var objs=eval(ret['JT']);
						var idfixandfirst=0;
						var idfixend=0;
						var idfixin=0;
						var idfirstend=0;
						var idfirstin=0;
						
						for(var k in ret['JT'])
							{
								YCM[k]=ret['JT'][k]['异常原因'];
								if(YCM[k]==='更换耗材'||YCM[k]==='工单切换调机'||YCM[k]==='设备故障调机'||YCM[k]==='生产调机首检'||YCM[k]==='换单首检'||YCM[k]==='换耗材首检'||parzz.test(ret['JT'][k]['异常码'])){
									//console.log(htmls);//+"--"+YCJT+"=="+YCM+"--"+YCSTARTTIMES
									
										var htmls="<td>"+ret['JT'][k]['YiChangJiTai']+"</td>"
										+"<td>"+ret['JT'][k]['异常原因']+"</td>"
										+"<td>"+ret['JT'][k]['报修人']+"</td>"
										+"<td>"+ret['JT'][k]['处理人']+"</td>"
										+"<td>"+ret['JT'][k]['处理人分组']+"</td>"
										+"<td>"+ret['JT'][k]['YiChangStartTime']+"</td>"
										+"<td>"+ret['JT'][k]['YiChangEndTime']+"</td>"
										+"<td>"+ret['JT'][k]['times']+"</td>"
										;
										
										var htmls1="<td>"+ret['JT'][k]['YiChangJiTai']+"</td>"
										+"<td>"+ret['JT'][k]['异常原因']+"</td>"
										+"<td>"+ret['JT'][k]['报修人']+"</td>"
										+"<td>"+ret['JT'][k]['处理人']+"</td>"
										+"<td>"+ret['JT'][k]['处理人分组']+"</td>"
										+"<td>"+ret['JT'][k]['YiChangStartTime']+"</td>"
										+"<td>"+ret['JT'][k]['times']+"</td>"
										;
									idfixandfirst+=1;
									var ID ="<td>"+idfixandfirst+"</td>";
									$("<tr></tr>")
									.append(ID)
									.append(htmls)
									.appendTo("#table_fixandfirst tbody ");//将td放入tr内在放入tbody
								
									if(ret['JT'][k]['YiChangEndTime']!==' '&&(YCM[k]==='更换耗材'||YCM[k]==='工单切换调机'||YCM[k]==='设备故障调机'||parzz.test(ret['JT'][k]['异常码']))){
										idfixend+=1;
										var ID ="<td>"+idfixend+"</td>";
										$("<tr></tr>")
										.append(ID)
										.append(htmls)
										.appendTo("#table_fixend tbody ");//将td放入tr内在放入tbody
									}
									if(ret['JT'][k]['YiChangEndTime']===' '&&(YCM[k]==='更换耗材'||YCM[k]==='工单切换调机'||YCM[k]==='设备故障调机'||parzz.test(ret['JT'][k]['异常码']))){
										idfixin+=1;
										var ID ="<td>"+idfixin+"</td>";
										$("<tr></tr>")
										.append(ID)
										.append(htmls1)
										.appendTo("#table_fixin tbody ");//将td放入tr内在放入tbody
									}
									if(ret['JT'][k]['YiChangEndTime']!==' '&&(YCM[k]==='生产调机首检'||YCM[k]==='换单首检'||YCM[k]==='换耗材首检')){
										idfirstend+=1;
										var ID ="<td>"+idfirstend+"</td>";
										$("<tr></tr>")
										.append(ID)
										.append(htmls)
										.appendTo("#table_QCend tbody ");//将td放入tr内在放入tbody
									}
									if(ret['JT'][k]['YiChangEndTime']===' '&&(YCM[k]==='生产调机首检'||YCM[k]==='换单首检'||YCM[k]==='换耗材首检')){
										idfirstin+=1;
										var ID ="<td>"+idfirstin+"</td>";
										$("<tr></tr>")
										.append(ID)
										.append(htmls1)
										.appendTo("#table_QCin tbody ");//将td放入tr内在放入tbody
									}
									
								}
								//OffEquips[k]=-(ret['JT'][k]['OffEquips']);
								
							}
						
					}
				});
			
			$(document).on("click", ".btn-checkversion", function(){
				top.window.$("[data-toggle=checkupdate]").trigger("click");
			});
			
		}
    };
    return Controller;
});